/*
 *英才会硕信息科技有限公司拥有本软件的版权，拥有本软件版权2025   并保留所有权利。
 *Copyright 2021,YCHS Information&Science Technology Co.,Ltd,
 *All rights reserved.
 */
package com.ychs.lawyerback01.interceptor.config;

import com.ychs.lawyerback01.interceptor.Logininterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpMethod;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author xuehongjin
 * @version 1.0
 * @date 2025/8/8
 */
@Configuration
public class WebConfig implements WebMvcConfigurer{
    @Autowired
    private Logininterceptor logininterceptor;

    @Value("${file.upload.backup-location}")
    private String uploadPath;
    /**
     * 跨域的配置
     * @param registry
     */
    @Override
    public void addCorsMappings(CorsRegistry registry){
       registry.addMapping("/**")
               .allowedOriginPatterns("*")
               .allowedMethods("*")
               .allowedHeaders("*")

               .allowCredentials(true);
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(logininterceptor)
                .addPathPatterns("/**")
//                .excludePathPatterns("/login","/logout","/documents/upload", "/documents/template");
                .excludePathPatterns(
                        "/login",
                        "/logout",
                        "/documents/upload",
                        "/documents/template"
                   //     "/documents/**"
                );
    }
}
